/*
 *  Copyright 2007 Blandware (http://www.blandware.com)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.blandware.atleap.service.core;

import com.blandware.atleap.common.util.PartialCollection;
import com.blandware.atleap.common.util.QueryInfo;
import com.blandware.atleap.model.core.Sequence;
import com.blandware.atleap.model.core.SequenceItem;
import com.blandware.atleap.persistence.exception.DeleteException;
import com.blandware.atleap.service.exception.BeanAlreadyExistsException;
import com.blandware.atleap.service.exception.BeanNotFoundException;

/**
 * <p>Business Delegate (Proxy) Interface to handle communication between web and
 * persistence layer.
 * </p>
 * <p><a href="SequenceManager.java.html"><i>View Source</i></a>
 * </p>
 *
 * @author Roman Puchkovskiy <a href="mailto:roman.puchkovskiy@blandware.com">
 *         &lt;roman.puchkovskiy@blandware.com&gt;</a>
 * @version : $Revision: 1.3 $ : 2007/12/17 13:38:25 $
 */
public interface SequenceManager extends BaseManager {

	//  S E Q U E N C E S

	//~ CRUD Methods ================================================================

	/**
	 * Creates sequence.
	 *
	 * @param sequence   Sequence to create
	 * @param ownerId ID of owner localizable to associate sequence with
	 * @return ID of created sequence
	 * @throws com.blandware.atleap.service.exception.BeanNotFoundException
     * if localizable with specified ID couldn't be found
	 * @throws com.blandware.atleap.service.exception.BeanAlreadyExistsException
     * if sequence with such identifier already exists on localizable with specified ID
	 */
	public Long createSequence(Sequence sequence, Long ownerId)
            throws BeanNotFoundException, BeanAlreadyExistsException;

	/**
	 * Retrieves sequence with specified ID.
	 *
	 * @param sequenceId the ID of sequence to retrieve
	 * @return Sequence or null if no sequence with specified ID exists in database
	 */
	public Sequence retrieveSequence(Long sequenceId);

	/**
	 * Updates sequence.
	 *
	 * @param sequence         Sequence to update
	 * @param localizableId ID of localizable to associate sequence with
	 * @throws com.blandware.atleap.service.exception.BeanNotFoundException
     * if localizable with specified ID couldn't be found
	 * @throws com.blandware.atleap.service.exception.BeanAlreadyExistsException
     * if sequence with such identifier already exists on localizable with specified ID
	 */
	public void updateSequence(Sequence sequence, Long localizableId)
            throws BeanNotFoundException, BeanAlreadyExistsException;

	/**
	 * Removes sequence.
	 *
	 * @param sequenceId ID of localizable sequence to remove
	 * @throws com.blandware.atleap.service.exception.BeanNotFoundException
     * if sequence with specified ID couldn't be found
	 * @throws com.blandware.atleap.persistence.exception.DeleteException
     * if sequence cannot be deleted (e.g. it has one or more associated values)
	 */
	public void deleteSequence(Long sequenceId)
            throws BeanNotFoundException, DeleteException;

	// ~ Additional methods ================================================================

	/**
	 * Retrieves filtered/sorted collection of sequences.
	 *
	 * @param queryInfo Object that contains information about how to filter and sort data
	 * @return Collection of sequences
	 */
	public PartialCollection listSequences(QueryInfo queryInfo);

	// ~ Finders ================================================================

	/**
	 * Finds sequence by layout definition and identifier.
	 *
	 * @param identifier Identifier of sequence to search by
	 * @param definition Struts tile definition on which layout is based
	 * @return Sequence or null if nothing was found
	 */
	public Sequence findSequenceByLayoutDefinition(String identifier, String definition);

	/**
	 * Finds sequence by page URI and identifier.
	 *
	 * @param identifier Identifier of sequence to search by
	 * @param uri        URI of page to which sequence belongs
	 * @return Sequence or null if nothing was found
	 */
	public Sequence findSequenceByPageUri(String identifier, String uri);


    //  S E Q U E N C E   I T E M S

    //~ CRUD Methods ================================================================

    /**
     * Creates new sequence item (it points to page).
     *
     * @param sequenceItem      Sequence item to create
     * @param sequenceId        ID of sequence to create item for
     * @param pageId            ID of page to which item points
     * @return ID of created sequence item
     * @throws BeanNotFoundException if sequence or page with specified ID
     * couldn't be found
     */
    public Long createPageSequenceItem(SequenceItem sequenceItem,
            Long sequenceId, Long pageId) throws BeanNotFoundException;

    /**
     * Creates new sequence item (it points to content resource).
     *
     * @param sequenceItem      Sequence item to create
     * @param sequenceId        ID of sequence to create item for
     * @param contentResourceId ID of content resource to which item points
     * @return ID of created sequence item
     * @throws BeanNotFoundException if sequence or content resource with
     * specified ID couldn't be found
     */
    public Long createContentResourceSequenceItem(SequenceItem sequenceItem,
            Long sequenceId, Long contentResourceId) throws BeanNotFoundException;

    /**
     * Retrieves sequence item with specified ID.
     *
     * @param sequenceItemId the id of item to retrieve
     * @return Sequence item or null if no sequence item with specified ID exists in database
     */
    public SequenceItem retrieveSequenceItem(Long sequenceItemId);

    /**
     * Updates sequence item (it will point to page).
     *
     * @param sequenceItem  The sequence item to update
     * @param sequenceId    ID of sequence to update item for
     * @param pageId        ID of page to which item will point
     * @throws BeanNotFoundException if sequence or page with specified ID
     * couldn't be found
     */
    public void updatePageSequenceItem(SequenceItem sequenceItem,
            Long sequenceId, Long pageId) throws BeanNotFoundException;

    /**
     * Updates sequence item (it will point to content resource).
     *
     * @param sequenceItem      The sequence item to update
     * @param sequenceId        ID of sequence to update item for
     * @param contentResourceId ID of content resource to which item will point
     * @throws BeanNotFoundException if sequence or content resource with
     * specified ID couldn't be found
     */
    public void updateContentResourceSequenceItem(SequenceItem sequenceItem,
            Long sequenceId, Long contentResourceId) throws BeanNotFoundException;

    /**
     * Removes sequence item with specified ID.
     *
     * @param sequenceItemId ID of sequence item to remove
     * @throws BeanNotFoundException if sequence item with specified ID couldn't be found
     */
    public void deleteSequenceItem(Long sequenceItemId) throws BeanNotFoundException;

    // ~ Additional methods ================================================================

    /**
     * Retrieves filtered/sorted collection of sequence items.
     *
     * @param queryInfo Object that contains information about how to filter and sort data
     * @return Collection of sequence items
     */
    public PartialCollection listSequenceItems(QueryInfo queryInfo);

    /**
     * Changes sequence item position.
     *
     * @param sequenceItem item to move
     * @param up whether item should raise in the list
     */
    public void moveSequenceItem(SequenceItem sequenceItem, boolean up);

    /**
     * Returns least and most positions of sequence item which sequence has
     * given ID.
     *
     * @param sequenceId ID of sequence which children will be considered
     * @return two-element array: least and most occupied positions
     */
    public Integer[] getSequenceItemFirstLastOccupiedPositions(Long sequenceId);

    // ~ Finders ================================================================    
}